home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_teTeX.idb / usr / freeware / bin / dvihp.z / dvihp
Text File  |  2001-01-10  |  5KB  |  129 lines

  1. #!/bin/sh
  2. # $Id: dvihp,v 1.3 1996/12/03 19:53:56 karl Exp karl $
  3. # Run dvicopy, then dvilj[k].  kb@mail.tug.org, 1994.  Public domain.
  4. # Try to accept arguments a la dvips, from Thomas Esser.
  5.  
  6. : ${DVILJ=dvilj4}       # the dvilj variant to run
  7. : ${SPOOL=lpr}          # used to print an LJ file
  8. : ${TMPDIR=/tmp}        # for the dvicopy output
  9.  
  10. TMPDIR=${TMPDIR}/dvihp$$
  11. mkdir $TMPDIR || { echo "cannot create directory \`$TMPDIR'."; exit 1; }
  12. trap 'cd /; rm -rf $TMPDIR; trap '' 0; exit 0' 0 1 2 3 6 7 13 15
  13.  
  14. rcs_revision='$Revision: 1.3 $'
  15. version=`set - $rcs_revision; echo $2`
  16.  
  17. usage="Usage: `basename $0` [OPTIONS] [DVIFILE[.dvi]].
  18.   Translate the given DVIFILE to Hewlett-Packard PCL by calling dvicopy
  19.   and then \$DVILJ (dvilj4 by default).
  20.   In the absence of other options, pipe the PCL to \$SPOOL (lpr by default).
  21.   
  22.   Options are recognized from dvips where possible:
  23. -A    print odd pages
  24. -B    print even pages
  25. -d #  set debug bits to # (see documentation)
  26. -D #  set resolution to #
  27. -f    run as filter
  28. -l #  don't print pages after #
  29. -m    manual feed
  30. -n #  print # pages
  31. -O #,#  set/change paper offset to #,# mm
  32. -o s  output to s instead of spooling
  33. -p #  don't print pages before #
  34. -Ps   pass directly to lpr
  35. -v    verbose operation
  36. -x #  set magnification to #
  37.  
  38. Other options are passed to the dvilj program.
  39.  
  40. Email bug reports to tex-k@mail.tug.org."
  41.  
  42.  
  43. if test $# -eq 0; then
  44.   echo "`basename $0`: Missing argument(s)." >&2
  45.   echo "Try \``basename $0` --help' for more information." >&2
  46.   exit 0
  47. fi
  48.  
  49. unset infile opt output
  50. output_opt=-e
  51. verbose=false
  52.  
  53. while test $# -gt 0; do
  54.   case "$1" in
  55.     -help|--help) echo "$usage"; exit 0;;
  56.     -version|--version) 
  57.       echo "`basename $0` (Dviljk 2.6) $version"
  58.       echo "There is NO warranty.  This script is public domain."
  59.       exit 0;;
  60.     -A)  opt="$opt -D1";;                       # -A => -D1 (odd pages)
  61.     -B)  opt="$opt -D2";;                       # -B -> -D2 (even pages)
  62.     -d)  shift; opt="$opt --D$1";;              # -d => --D (debug)
  63.     -d*) opt="$opt `echo $1 | sed s/d/-D/`";;
  64.     -D)  shift; opt="$opt -R$1";;               # -D => -R (resolution)
  65.     -f)  infile=; output=-;;                    # -f (run as filter)
  66.     -l)  shift; opt="$opt -t$1";;               # -l => -t (ending page)
  67.     -l*) opt="$opt `echo $1 | sed s/l/t/`";;
  68.     -m)  opt="$opt -A";;                        # -m => -A (manual feed)
  69.     -n)  shift; opt="$opt -p$1";;               # -n => -p (page count)
  70.     -n*) opt="$opt `echo $1 | sed s/^-n/-p/`";;
  71.     -o)  if test $# -eq 1; then                 # -o (output file)
  72.            # No remaining args, output to foo.lj.
  73.            output=`basename $infile .dvi`.lj
  74.          else shift; output="$1"; fi;;
  75.     -o*) output="`echo $1 | sed 's/^-o//'`";;
  76.     -O)  shift; x=`echo $1 | sed 's/,.*//'`     # -O => -x, -y (page offsets)
  77.          y=`echo $1 | sed 's/.*,//'`;  opt="$opt -x$x -y$y";;
  78.     -O*) temp="`echo $1 | sed 's/^-O//'`"
  79.          x=`echo $temp | sed 's/,.*//'`
  80.          y=`echo $temp | sed 's/.*,//'`;
  81.          opt="$opt -x$x -y$y";;
  82.     -p)  shift; opt="$opt -f$1";;               # -p => -f (starting page)
  83.     -p*) opt="$opt `echo $1 | sed s/p/f/`";;
  84.     -P)  shift; output=; spool_opt="-P$1";;     # -Pprinter
  85.     -P*) output=; spool_opt="$1";;
  86.     -v)  verbose=true; opt="$opt -v";;
  87.     -x)  shift; opt="$opt -m$1";;               # -x => -m (magnification)
  88.     -x*) opt="$opt `echo $1 | sed s/x/m/`";;
  89.     --)  shift; infile="$1"; break;;            # -- => end of options
  90.     -*)  opt="$opt $1";;                        # pass other options through
  91.     *)   infile="$1";;
  92.   esac
  93.   shift
  94. done
  95.  
  96. # Make sure the filenames are unique on MS-DOS
  97. vfless_dvi=$TMPDIR/dvi$$.vf
  98. dvicopy_log=$TMPDIR/dvi$$.copy
  99. dvilj_log=$TMPDIR/dvi$$.lj
  100.  
  101. # Expand VF references.
  102. # If $infile is null, this will read standard input.
  103. # dvilj can't read from a pipe, so always write to a file.
  104. $verbose && echo "Running dvicopy $infile >$vfless_dvi" >&2
  105. if dvicopy $infile >$vfless_dvi; then :; else
  106.   echo "$0: dvicopy $infile failed." >&2
  107.   exit 1
  108. fi
  109. $verbose && ls -l $vfless_dvi >&2
  110.  
  111. if test -z "$output"; then
  112.   output=- # output to stdout
  113.   # Doing this pipe means the true exit status might get lost, but it
  114.   # seems worth it to avoid the temporary file. (Bad enough to have one.)
  115.   maybe_spool_cmd="| $SPOOL $spool_opt"
  116. else
  117.   maybe_spool_cmd=
  118. fi
  119.  
  120. # Translate DVI to LJ.
  121. cmd="$DVILJ $opt $output_opt$output $vfless_dvi $maybe_spool_cmd"
  122. $verbose && echo "Running $cmd" >&2
  123. if eval $cmd; then :; else
  124.   echo "$0: $DVILJ failed." >&2
  125.   exit 2
  126. fi
  127.  
  128. rm -f $TMPDIR/dvi$$.*
  129.